var express = require('express');
var router = express.Router();

let { studentModel } = require("../models/studentModel")

//注册
router.post("/register", async (req, res, next) => {
    let { phone, password } = req.body
    if (phone != "" && password != "") {
        let datas = await studentModel.find({ phone: req.body.phone, password: req.body.password })
        // console.log(datas);
        if (datas.length == 0) {
            let data = await studentModel.create(req.body)
            res.send({
                message: '注册成功',
                code: 200,
                data: data
            })
        } else {
            res.send({
                message: '账号已经存在或没有输入',
                code: 201
            })
        }
    } else {
        res.send({
            message: '账号或密码不能为空',
            code: 202
        })
    }

});
module.exports = router;